﻿@model TestOnlineProject.Models.Entities.Report
@using TestOnlineProject.Common
@using TestOnlineProject.Models.Entities
@{
    ViewBag.Title = "Details";
}
@{
    if (!String.IsNullOrEmpty(ViewBag.Msg))
    {
    <script>        alert("@ViewBag.Msg")</script>
    }
}
<script>
    $(document).ready(function () {
        $("#deactivate").click(function () {
        var con = confirm("Are you sure you want to mark as unread this report?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/Report/Uncheck")" + "?ids=" + @Model.ReportId + "-",
                    type: 'GET',
                    success: function (data) {
                    alert(data);
                        if (data != null) {
                            window.location = "@Url.Content("~/Report/Details")" + "?id=" + @Model.ReportId;
                        }
                    }
                })
                }
        }); $("#activate").click(function () {
        var con = confirm("Are you sure you want to mark as read this report?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/Report/Check")" + "?ids=" + @Model.ReportId + "-",
                    type: 'GET',
                    success: function (data) {
                    alert(data);
                        if (data != null) {
                            window.location = "@Url.Content("~/Report/Details")" + "?id=" + @Model.ReportId;
                        }
                    }
                })
                }
        });

        $("#delete").click(function () {
        var con = confirm("Are you sure you want to delete this report?");
            if (con == true) {
                $.ajax({
                    url: "@Url.Content("~/Report/Delete")" + "?ids=" + @Model.ReportId + "-",
                    type: 'GET',
                    success: function (data) {
                    alert(data);
                        if (data != null) {
                            window.location = "@Url.Content("~/Report/Index")";
                        }
                    }
                })
                }
        });
    })
</script>
<div class="site_map">
    @Html.ActionLink("Home", "Index", "Home") / @Html.ActionLink("Reports", "Index", "Report")
    / <span style="word-wrap: break-word">@Model.Message</span>
</div>
<br />
<div class="main_nav">
    <span><a href="@Url.Content("~/Report/Index")">
        <img src="@Url.Content("~/Images/back button.png")" style="height:30px"/>
    </a></span>
</div>
<br />
@{
    if (!Model.IsChecked)
    {
    <div class="alert alert-warning">
        <span>Unread.</span>
    </div>
    }
}
<table class="table table-bordered" style="table-layout: fixed">
    @{
        if (Model.QuestionId > 0)
        {
        <tr>
            <td style="width: 150px; text-align: right">
                <span>Question</span>
            </td>
            <td>
                @Html.ActionLink("Details", "Details", "Question", new { id = @Model.QuestionId }, new { target = "_blank" })
            </td>
        </tr>
        }
        if (Model.DiscussionId > 0)
        {
        <tr>
            <td style="width: 150px; text-align: right">
                <span>Discussion</span>
            </td>
            <td>
                @Html.ActionLink("Details", "Details", "Discussion", new { discussionId = @Model.DiscussionId, thread = @Model.DiscussionId }, new { target = "_blank" })
            </td>
        </tr>
        }
        if (Model.SectionId > 0)
        {
        <tr>
            <td style="width: 150px; text-align: right">
                <span>Section</span>
            </td>
            <td>
                @Html.ActionLink("Details", "Details", "Section", new { id = @Model.SectionId }, new { target = "_blank" })
            </td>
        </tr>
        }
        if (Model.TestId > 0)
        {
        <tr>
            <td style="width: 150px; text-align: right">
                <span>Test</span>
            </td>
            <td>
                @Html.ActionLink("Details", "Details", "Test", new { id = @Model.TestId }, new { target = "_blank" })
            </td>
        </tr>
        }
    }
    <tr>
        <td style="width: 150px; text-align: right">
            <span>Reported By</span>
        </td>
        <td>
            @Html.ActionLink(Model.User.FullName, "Index", "Account", new { userId = @Model.UserId }, new { target = "_blank" })
        </td>
    </tr>
    <tr>
        <td style="width: 150px; text-align: right">
            <span>Message</span>
        </td>
        <td>
            <span style="word-wrap: break-word">@Html.DisplayFor(model => model.Message)</span>
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            <span>Created Time</span>
        </td>
        <td>
            @Html.DisplayFor(model => model.CreatedTime)
        </td>
    </tr>
    <tr>
        <td style="text-align: right">
            <span>Similar</span>
        </td>
        <td>
            @{
                var reports = ViewBag.Reports as List<Report>;
                var number = 0;

                if (Model.QuestionId != null)
                {
                    foreach (var report in reports.Where(r => r.QuestionId == Model.QuestionId))
                    {
                        if (!report.IsChecked)
                        {
                            number++;
                        }
                    }
                }

                if (Model.TestId != null)
                {
                    foreach (var report in reports.Where(r => r.TestId == Model.TestId))
                    {
                        if (!report.IsChecked)
                        {
                            number++;
                        }
                    }
                }

                if (Model.DiscussionId != null)
                {
                    foreach (var report in reports.Where(r => r.DiscussionId == Model.DiscussionId))
                    {
                        if (!report.IsChecked)
                        {
                            number++;
                        }
                    }
                }

                if (Model.SectionId != null)
                {
                    foreach (var report in reports.Where(r => r.SectionId == Model.SectionId))
                    {
                        if (!report.IsChecked)
                        {
                            number++;
                        }
                    }
                }
                
                <span>@number</span>
            }
        </td>
    </tr>
    @* <tr>
        <td style="text-align: right">
            <span>Checked</span>
        </td>
        <td>
            @{
                if (Model.IsChecked)
                {
                <span>Yes</span>
                }
                else
                {
                <span>No</span>
                }
            }
        </td>
    </tr>*@
    <tr>
        <td>
        </td>
        <td>
            @{
                if (Model.IsChecked)
                {
                <a href="#" id="deactivate">Mark as unread</a>
                }
                else
                {
                <a href="#" id="activate">Mark as read</a>
                }
                <span>|</span>
            }
            <a href="#" id="delete">Delete</a>
        </td>
    </tr>
</table>
